package application.dispatcher;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;

import org.dsrg.soenea.domain.command.CommandException;

import domain.command.RemoveGroupCommand;

public class RemoveGroupDispatcher extends Dispatcher
{



	public void execute() throws ServletException, IOException 
	{

		String requestMethod = this.myRequest.getMethod();
		boolean isPost =  "POST".equals(requestMethod);


		try
		{	
			new RemoveGroupCommand(myHelper, isPost).execute();

			if( isAjax() ) 
			{
				// ajax call
				PrintWriter out = myResponse.getWriter();
				myResponse.setContentType("text/plain");
				out.println("A group has been removed!");
			} 
			else 
			{
				myHelper.setRequestAttribute("viewFile", "RemoveGroupTV");
				forward("/WEB-INF/JSP/template/template.jsp");
			}

			return;

		}
		catch (CommandException e)
		{
			forward("/WEB-INF/JSP/Errors.jsp");
			//e.printStackTrace();
		}
	}
}
